package com.gitee.wsl.config.pref

import com.gitee.wsl.data.store.StoreServer
import com.gitee.wsl.data.store.getPreferenceOrNull
import kotlin.reflect.KProperty

internal class StringNullablePref(
    val default: String?,
    override val key: String?,
    private val commitByDefault: Boolean
) : AbstractPref<String?>() {

    override fun getFromPreference(property: KProperty<*>, preference: StoreServer): String? {
        return preference.getPreferenceOrNull<String>(preferenceKey)?:default
    }

    override fun setToPreference(property: KProperty<*>, value: String?, preference: StoreServer) {
        if(value == null)
            preference.remove(preferenceKey)
        else
            preference.putPreference(preferenceKey,value)
    }
}